package com.longteng.java.web.dataproducer;

import com.google.common.collect.Lists;
import com.google.common.io.Resources;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * Created by tianqing.wang
 * DATE : 2018/3/11
 * TIME : 下午5:12
 * PROJECT : java-lesssion
 * PACKAGE : com.gitee.longteng.lession.lesson2.dataproducer
 *
 * @author <a href="mailto:celeskyking@163.com">tianqing.wang</a>
 */
public class PhoneNumberDataGenerator implements DataGenerator<String>{


    private static final String PHONE_PREFIX_FILE = "phone_prefix.txt";


    private List<String> phonePrefix = Lists.newArrayList();



    public PhoneNumberDataGenerator() {
        List<String> lines;
        try {
            URL url = Resources.getResource(PHONE_PREFIX_FILE);
            lines = Resources.readLines(url, StandardCharsets.UTF_8);
            phonePrefix.addAll(lines);
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }

    }

    @Override
    public String generate() {
        return String.valueOf(phonePrefix.get(RandomUtil.getRandom(0,phonePrefix.size()-1))) + RandomUtil.getRandom(10000000,99999999);

    }

}
